package sk.patt.eshop.pages.admin;

import java.util.List;

import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable;
import org.apache.wicket.extensions.markup.html.repeater.data.table.HeadersToolbar;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.NavigationToolbar;
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;

import sk.patt.eshop.BrandsProvider;
import sk.patt.eshop.data.dao.interfaces.BrandDao;
import sk.patt.eshop.data.dataobjects.Brand;
import sk.patt.eshop.data.dataobjects.Event;

public class AdminBrandsPage extends AdminPage {

	@SpringBean
	private BrandDao brandDao;
		
	private TextField<String> brandTitle;
	private BrandsProvider brandsProvider = new BrandsProvider(brandDao);
	
	public AdminBrandsPage() {
		IColumn[] columns = new IColumn[2];
		columns[0] = new PropertyColumn(new Model<String>("Brand ID"), "id", "id");
		 columns[1] = new PropertyColumn(new Model<String>("Brand name"), "title", "title");
		 
		 DataTable table = new DataTable("datatable", columns, brandsProvider, 10);
		 
		 table.addBottomToolbar(new NavigationToolbar(table));
		 table.addTopToolbar(new HeadersToolbar(table, brandsProvider));
		 add(table);
		 
		brandTitle = new TextField<String>("brandTitle", Model.of(""));
		brandTitle.setRequired(true);
		
		Form<Brand> brandForm = new Form<Brand>("insertBrandForm"){
			@Override
			protected void onSubmit() {
				Brand newBrand = new Brand();
				newBrand.setTitle(brandTitle.getInput());
				brandDao.save(newBrand);
				List<Brand> brandsss = brandDao.findAll();
				for (Brand b:brandsss) {
					System.out.println(b.getTitle());
				}
			}
		};
		
		add(brandForm);
		brandForm.add(brandTitle);
	}
}
